package com.pk.patterns;
// http://pl.wikisource.org/wiki/Metoda_wytw%C3%B3rcza_(wzorzec_projektowy)/kod

import javax.swing.*; 
import javax.swing.table.AbstractTableModel;

import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.Connection;
import java.sql.DriverManager;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;

abstract class Vehicle {
	private String status = "";
	
	
    public abstract boolean sell();
    public abstract boolean buy();
    public abstract boolean borrow();
}

interface t {
	public abstract boolean buy();
}

class rrr implements t {

	@Override
	public boolean buy() {
		
		
		ArrayList <CarVehicle> yy = new ArrayList <CarVehicle> ();
		
		HashMap  te = new HashMap <String,CarVehicle> ();
		
		te.put("object1",new CarVehicle());
		
		
		CarVehicle car = (CarVehicle)te.get("object1");
		
		car.buy();
		
		CarVehicle r = (CarVehicle)yy.get(3);
		
		
		new t () {

			@Override
			public boolean buy() {
				// TODO Auto-generated method stub
				return false;
			}
			
		};
		
		
		return false;
	}
	
	
}


class CarVehicle extends Vehicle {

	@Override
	public boolean sell() {
		return false;
	}

	@Override
	public boolean buy() {
		return false;
	}

	@Override
	public boolean borrow() {
		
		
		
		VehicleFactory.VehicleType tr;
		
		tr = VehicleFactory.VehicleType.CarVehicle;
		
		return false;
	}

}


class VehicleFactory {
     public enum VehicleType {
    	CarVehicle,
    	wewe
    }
    
    public static Vehicle createVehicle(VehicleType vehicleType) {
        switch (vehicleType) {
            case CarVehicle:
                return new CarVehicle();
        }
        throw new IllegalArgumentException("The pizza type " + vehicleType + " is not recognized.");
    }
}

class MainWindow extends JFrame{
	
	public MainWindow() {
		
		new Vehicle() {
			@Override
		    public  boolean sell() {
				return true;
		    }
			@Override
		    public  boolean buy() {
				return true;
		    }
			@Override
		    public  boolean borrow() {
		    	return true;
		    }
		};
		
		
		String[] columnNames = {"First Name",
                "Last Name",
                "Sport",
                "# of Years",
                "Vegetarian"};
		
		Object[][] data = {
			    {"Kathy", "Smith",
			    	new Date("12/07/1941"), new Integer(5), new Boolean(false)},
			    {"John", "Doe",
			     "Rowing", new Integer(3), new JButton()},
			    {"Sue", "Black",
			     "Knitting", new Integer(2), new Boolean(false)},
			    {"Jane", "White",
			     "Speed reading", new Integer(20), new Boolean(true)},
			    {"Joe", "Brown",
			     "Pool", new Integer(10), new Boolean(false)}
			};
		
		JTable table = new JTable(data, columnNames);
		
		
		/* new AbstractTableModel() {
		    public String getColumnName(int col) {
		        return columnNames[col].toString();
		    }
		    public int getRowCount() { return rowData.length; }
		    public int getColumnCount() { return columnNames.length; }
		    public Object getValueAt(int row, int col) {
		        return rowData[row][col];
		    }
		    public boolean isCellEditable(int row, int col)
		        { return true; }
		    public void setValueAt(Object value, int row, int col) {
		        rowData[row][col] = value;
		        fireTableCellUpdated(row, col);
		    }
		} */

		
		System.setProperty("com.apple.mrj.application.apple.menu.about.name", "Komis samochodowy");
		
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setVisible(true);
		
		JButton sellButton = new JButton();
		
		setLayout(new BorderLayout());  
		
		this.add(table,BorderLayout.NORTH);
		add(sellButton, BorderLayout.SOUTH);  
		
		sellButton.addActionListener(new ActionListener(){

			@Override
			public void actionPerformed(ActionEvent e) {
				System.out.print("String argument");
				
			}
			
		});
		
		sellButton.setBounds(10, 10, 200, 40);
		sellButton.setSize(40, 200);
		
		sellButton.setText("sell");

	}
}


class Komis {
    /**
     * Create the GUI and show it.  For thread safety,
     * this method should be invoked from the
     * event-dispatching thread.
     */
    private static void createAndShowGUI() {
        //Create and set up the window.
        JFrame frame = new JFrame("TableToolTipsDemo");
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
 
        //Create and set up the content pane.
        JComponent newContentPane = new MainFrame();
        newContentPane.setOpaque(true); //content panes must be opaque
        frame.setContentPane(newContentPane);
 
        //Display the window.
        frame.pack();
        frame.setVisible(true);
    }
    
    static String  dbURL=new String("jdbc:postgresql:127.0.0.1:5432/test");
    String rrrr = "";
    
    private void sdfs () {
    	rrrr = "sd";
    }
    
    static boolean sdfgadsf () {
    	System.out.print("sdf");
    
    	
    	try {
    		
    		return true;
    	} catch (Exception e) {
    		return true;
    	}
    }
    
	public static void main (String args[]) throws Exception {
    /*    for (VehicleFactory.VehicleType pizzaType : VehicleFactory.VehicleType.values()) {
            //System.out.println("Price of " + pizzaType + " is " + PizzaFactory.createVehicle(pizzaType).getPrice());
        }
        
        new MainWindow();
     */
		//try {
			Class.forName("org.postgresql.Driver");
			
			//Connection conn=DriverManager.getConnection(dbURL, "testpostgers", "test");
			
			//Cursor cu = conn.getC
			
		//} catch (Exception e) {
		//	System.out.print(e.toString());
		//}
			
        javax.swing.SwingUtilities.invokeLater(new Runnable() {
            public void run() {
                createAndShowGUI();
            }
        });
    }
}




class X {
	void metoda1 () {
		Budynek budynek = new Budynek ();
		budynek.metoda();
	}
}



